﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ivy.Common.Framework.SqlServerUtility
{
    public class SqlServerUtility
    {
        #region Variables & Constants
        #endregion Variables & Constants

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Public Properties
        #endregion Public Properties

        #region Public Methods
        static public System.Data.DataTable GetSQLServerList()
        {
            try
            {
                System.Data.Sql.SqlDataSourceEnumerator lSqlInstance = System.Data.Sql.SqlDataSourceEnumerator.Instance;
                System.Data.DataTable lTableServerList = lSqlInstance.GetDataSources();
                return lTableServerList;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
        }

        static public System.Data.DataTable GetSQLServerDatabaseList(string pConnectionString)
        {
            try
            {
                System.Data.SqlClient.SqlConnection lSqlConnection = new System.Data.SqlClient.SqlConnection(pConnectionString);
                lSqlConnection.Open();
                System.Data.DataTable lTableDatabaseList = lSqlConnection.GetSchema("Databases");
                lSqlConnection.Close();
                return lTableDatabaseList;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
        }

        static public System.Data.DataTable GetSQLServerDbTableList(string pConnectionString, string DatabaseName)
        {
            try
            {
                System.Data.SqlClient.SqlConnection lSqlConnection = new System.Data.SqlClient.SqlConnection(pConnectionString);
                lSqlConnection.Open();
                System.Data.DataTable lTableDatabaseList = lSqlConnection.GetSchema("Tables");
                lSqlConnection.Close();
                return lTableDatabaseList;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
        }
        #endregion Public Methods

        #region Events
        #endregion Events

        #region Private Methods
        #endregion Private Methods
    }
}
